<template>
  <div class="fjscreen-header">
    <div class="header-warp">
      <img class="goback" @click="back" src="@/assets/images/fjscreen/fanhui.png" alt="返回">
      <div class="header-title-bg">
        <h3>{{ site_title }}-分拣大屏</h3>
      </div>
      <!-- <h3>菜东家生鲜供应链管理-分拣大屏</h3> -->
      <div class="header-right">
        <p>{{ currentDate }}</p>
        <!-- <img class="goback mg-r-16" src="@/assets/images/fjscreen/setting.png" alt="设置"> -->
        <img class="goback" v-if="showVolume" @click="playVolume" src="@/assets/images/fjscreen/volume-notice.png" alt="播放">
        <img class="goback" v-else @click="playVolume" src="@/assets/images/fjscreen/volume-mute.png" alt="静音">
      </div>
      <div class="scrollz">
        <transition-group name="slide" class="scroll-container1">
        <img
          v-for="(image, index) in images"
          :key="index * 651"
          :src="image"
          :style="{ transform: `translateX(${offset}px)` }"
        />
      </transition-group>
      </div>
      <div class="scroll-right">
        <transition-group name="slide" class="img-you">
          <img
            v-for="(image, index) in imagey"
            :key="index * 542"
            :src="image"
            :style="{ transform: `translateX(${offset2}px)` }"
          />
        </transition-group>
      </div>
    </div>
  </div>
</template>

<script>
import { parseTime } from "@/utils/index";
import { mapGetters } from "vuex";
export default {
  props: {
    showVolume: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      images: [
        require("@/assets/images/fjscreen/img-zuo.png"),
        require("@/assets/images/fjscreen/img-zuo.png"),
      ],
      imagey: [
        require("@/assets/images/fjscreen/img-you.png"),
        require("@/assets/images/fjscreen/img-you.png"),
      ],
      offset: 0,
      offset2: 0,
      times: null,
      currentDate: parseTime(new Date()),
      timer: null
    }
  },
  mounted() {
    this.times = setInterval(() => {
      if (this.offset <= -585) {
        this.offset = 0;
      } else {
        this.offset -= 5; // 每次移动5像素
      }

      if (this.offset2 >= 585) {
        this.offset2 = 0;
      } else {
        this.offset2 += 5; // 每次移动5像素
      }
    }, 20);
    this.timer = setInterval(() => {
      this.currentDate = parseTime(new Date());
    }, 1000);
  },
  computed: {
    ...mapGetters(["site_title"]),
  },
  beforeDestroy() {
    clearInterval(this.times);
    clearInterval(this.timer);
  },
  methods: {
    // 返回
    back() {
      this.outFullCreeen();
      this.$nextTick(() => {
        this.$router.push('/');
      });
    },
    outFullCreeen() {
      let element = document;
      let requestMethod =
        element.cancelFullScreen ||
        element.webkitCancelFullScreen ||
        element.mozCancelFullScreen ||
        element.exitFullScreen;
      if (requestMethod) {
        requestMethod.call(element);
      } else if (typeof window.ActiveXObject !== "undefined") {
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
          wscript.SendKeys("{F11}");
        }
      }
    },
    playVolume() {
      this.$emit('playVolume')
    }
  }
}
</script>
<style lang="scss" scoped>
.fjscreen-header {
  width: 100%;
  height: 111px;
  position: relative;
  .header-warp {
    display: flex;
    justify-content: space-between;
    padding: 0 30px 0;
    position: relative;
    .header-title-bg {
      width: 888px;
      height: 150px;
      background-image: url('../../assets/images/fjscreen/header-bg2.png');
      background-size: 100% 100%;
      background-repeat: no-repeat;
      background-position: center center;
      display: flex;
      justify-content: center;
      align-items: flex-start;
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      padding: 0 100px 0 140px;
      h3 {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 36px;
        color: #FFFFFF;
        background: linear-gradient(0deg, #439CCA 0%, #FFFFFF 78.5888671875%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-top: 10px;
      }
    }
    .header-title {
      width: 570px;
      height: 70px;
      background-image: url('../../assets/images/fjscreen/header-title.png');
      background-size: 100% 100%;
      background-repeat: no-repeat;
    }
    .goback {
      margin-top: 10px;
      position: relative;
      z-index: 2;
    }
    .header-right {
      display: flex;
      margin-top: 10px;
      p {
        font-family: PingFang SC;
        color: #DEF1FF;
        margin: 3px 10px 0 0;
      }
      img {
        margin-top: 0;
      }
    }
  }
  img {
    width: 24px;
    height: 24px;
    cursor: pointer;
  }
  .scrollz {
    position: absolute;
    z-index: 1;
    width: 582px;
  }
  .scroll-right {
    position: absolute;
    z-index: 1;
    width: 582px;
    right: 0;
  }
  .scroll-container1 {
    position: absolute;
    left: 0;
    width: 582px;
    display: flex;
    overflow: hidden;
    // z-index: 1;
    img {
      width: 100%;
      height: 53px;
    }
  }
  .img-you {
      position: absolute;
      right: 0;
      width: 582px;
      display: flex;
      overflow: hidden;
      justify-content: center;
       img {
        width: 100%;
        height: 53px;
      }
    }
  .slide-enter-active,
  .slide-leave-active {
    transition: transform 0.5s;
  }

  .slide-enter,
  .slide-leave-to {
    transform: translateX(0);
  }
  @keyframes slide-animation {
    0% {
      transform: translateX(0);
    }
    100% {
      transform: translateX(-485px); // 一共移动585像素
    }
  }

  .slide-move {
    animation: slide-animation 5s linear infinite;
  }
}
</style>